<template>
	<view class="box">
		<view class="box-header">
			<view class="header-nav" :class="isActive === 0? 'active' : ''" @click="chooseType(0)">问诊中</view>
			<view class="header-nav" :class="isActive === 1? 'active' : ''" @click="chooseType(1)">历史问诊</view>
		</view>

		<view class="box-list" v-show="list.length==0">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无记录">
			</u-empty>
		</view>

		<view class="box-list" v-show="list.length>0">
			<!-- 问诊列表 -->
			<view class="list-count" v-for="(item,index) in list" v-show="isActive === 0" :key="index">
				<view class="count-header">
					<view class="header-left">
						<text>订单号: {{item.orderNum}}</text>
						<u-button type="success" text="复制" style="width: 100rpx;" size="mini"
							@click="copy(item.orderNum)"></u-button>
					</view>
					<text class="money">¥ {{item.consultationFee==0.00?'免费':item.consultationFee}}</text>
				</view>
				<view class="count-body" @click="toNav(item)">
					<view class="body-header">
						<text>{{item.client.realName}}</text>
						<view class="header-back">{{item.client.sex===1?'男':'女'}}</view>
						<view class="header-back">{{item.client.age}}岁</view>
					</view>
					<view class="body-text">发病时间 : {{item.morbidityCondition==1?'复诊':item.morbidityTime}}
					</view>
			
					<view>
							<u--text :lines="2" :text="'主要临床表现：发热第'+item.feverDayNum +'天;最高'+item.highTemperature+'度;'+(!item.symptomDetail||item.symptomDetail==null?'':item.symptomDetail)" size="22rpx"></u--text>
					</view>
				</view>
				<view class="count-footer">
					<view>医生信息</view>
					<view class="list-box">
						<image src="@/static/image/doctor.jpg" mode=""></image>
						<view class="list-count1">
							<text>{{item.doctorUser.realName}} | {{item.doctorUser.occupationTitle}}</text>
							<text class="title">{{item.doctorUser.hospital}} | {{item.doctorUser.administrativeOffice}}</text>
							<view class="count">
								<u--text :lines="2" :text="'擅长：'+item.doctorUser.personalExpertise" size="22rpx"></u--text>
							</view>
						</view>
						<view class="list-btn">
							<u-button @click="toChat(item)" type="success" size="mini" shape="circle"
								color="#ffb049">立即沟通</u-button>
						</view>
					</view>
				</view>
			</view>
			<!-- 历史问诊列表 -->
			<view class="list-count" v-for="(item,index) in list" v-show="isActive === 1" :key="item.id">
				<view class="count-header">
					<view class="header-left">
						<text>订单号: {{item.orderNum}}</text>
						<u-button type="success" text="复制" style="width: 100rpx;" size="mini"
							@click="copy(item.orderNum)"></u-button>
					</view>
					<text class="money">¥ {{item.consultationFee==0.00?'免费':item.consultationFee}}</text>
				</view>
				<view class="count-body" @click="toNav(item)">
					<view class="body-header">
						<text>{{item.client.realName}}</text>
						<view class="header-back">{{item.client.sex===1?'男':'女'}}</view>
						<view class="header-back">{{item.client.age}}岁</view>
					</view>
					<view class="body-text">发病时间 : {{item.morbidityCondition==1?'复诊':item.morbidityTime}}
					</view>
					<view>
							<u--text :lines="2" :text="'主要临床表现：发热第'+item.feverDayNum +'天;最高'+item.highTemperature+'度;'+(!item.symptomDetail||item.symptomDetail==null?'':item.symptomDetail)" size="22rpx"></u--text>
					</view>
				</view>
				<view class="count-footer">
					<view>医生信息</view>
					<view class="list-box">
						<image src="@/static/image/doctor.jpg" mode=""></image>
						<view class="list-count1">
							<text>{{item.doctorUser.realName}} | {{item.doctorUser.occupationTitle}}</text>
							<text class="title">{{item.doctorUser.hospital}} | {{item.doctorUser.administrativeOffice}}</text>
							<view class="count">
								<u--text :lines="2" :text="'擅长：'+item.doctorUser.personalExpertise" size="22rpx"></u--text>
							</view>
						</view>
						<view class="list-btn">
							<u-button type="warning" size="mini" shape="circle" v-if="item.status===2">待接诊</u-button>
							<u-button type="success" size="mini" shape="circle" v-if="item.status===3"
								@click="toChat(item)">立即沟通</u-button>
							<u-button type="success" size="mini" shape="circle" v-if="item.status===4"
								color="#bbbbbb">已完结</u-button>
						</view>
					</view>
					<u-button type="success" height="50rpx" shape="circle" color="#54b6ab" v-if="item.status===4"
						@click="toResult(item.id)">医生接诊结果</u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isActive: 0,
				list: []
			};
		},
		onLoad(option) {
			if (option.type == 1) {
				this.isActive = 0
			} else {
				this.isActive = 1
			}
			console.log(this.isActive)
			this.findConsultationRecord(this.isActive == 0 ? 1 : 2)
		},
		onBackPress(e) {
			//backbutton 是点击物理按键返回，navigateBack是uniapp中的返回（比如左上角的返回箭头）
			if (e.from === 'backbutton') {
				uni.switchTab({
					url: '/pages/home'
				})
				return true // 阻止返回
			}
			console.log(e);
		},
		methods: {
			toNav(obj) {
				if(obj.status===4){
					return uni.showToast({
						icon:'none',
						title:'该问诊已结束'
					})
				}
				uni.setStorageSync('setRecordId', obj.id)
				uni.switchTab({
					url: '/pages/nav'
				})
			},
			//查看诊断结果
			toResult(id) {
				uni.navigateTo({
					url: '/pages/consultationResults?id=' + id
				})
			},
			//复制订单号
			copy(orderNum) {
				uni.setClipboardData({
					data: orderNum, //要被复制的内容
					success: () => { //复制成功的回调函数
						uni.showToast({ //提示
							icon: 'none',
							title: '复制成功'
						})
					}
				});
			},
			//切换
			chooseType(type) {
				this.isActive = type
				this.findConsultationRecord(this.isActive == 0 ? 1 : 2)
			},
			toChat(obj) {
				uni.navigateTo({
					url: '/pages/chat?name=' + obj.doctorUser.realName + "&userId=" + obj.doctorId+"&clientName="+obj.client.realName
				})
			},
			//查询问诊记录
			async findConsultationRecord(type) {
				const {
					data
				} = await uni.$http.post('/patient-interrogationRecords/findListByType?type=' + type)
				if (data.code === 200) {
					this.list = data.data
				}
			}
		}
	}
</script>

<style lang="scss">
	.box {
		width: 100%;
		height: 100%;
		background-color: #f2f2f2;
		overflow: auto;

		.box-header {
			width: 100%;
			height: 7%;
			background-color: #fff;
			display: flex;
			align-items: center;
			justify-content: space-around;

			.header-nav {
				width: 20%;
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				box-sizing: border-box;
				transition: all .3s;
			}

			.active {
				color: #54b6ab;
				border-bottom: 8rpx solid #54b6ab;
			}
		}

		.box-list {
			width: 100%;
			height: 90%;
			padding: 20rpx;
			margin-bottom: 20rpx;
			box-sizing: border-box;

			.list-count {
				width: 100%;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 20rpx;
				margin-bottom: 20rpx;
				box-sizing: border-box;

				.count-header {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.header-left {
						display: flex;
						align-items: center;

						text {
							margin-right: 20rpx;
						}
					}

					.money {
						color: red;
						font-weight: bold;
					}
				}

				.count-body {
					margin: 20rpx 0;
					width: 100%;
					padding: 20rpx;
					box-sizing: border-box;
					background-color: #f2f2f2;

					.body-header {
						display: flex;
						align-items: center;

						.header-back {
							margin: 0 20rpx;
							padding: 5rpx 20rpx;
							border-radius: 8rpx;
							background-color: #54b6ab;
							color: #fff;
						}
					}

					.body-text {
						margin: 10rpx 0;
						box-sizing: border-box;
					}
				}

				.count-footer {
					width: 100%;

					.list-box {
						width: 100%;
						padding: 20rpx;
						box-sizing: border-box;
						display: flex;
						align-items: stretch;
						justify-content: space-between;

						image {
							width: 100rpx;
							height: 100rpx;
						}

						.list-count1 {
							width: calc(100% - 300rpx);
							display: flex;
							flex-direction: column;

							.title {
								margin: 10rpx 0;
							}

							.count {
								word-break: break-all;
								text-overflow: ellipsis;
								display: -webkit-box;
								-webkit-box-orient: vertical;
								-webkit-line-clamp: 2;
								overflow: hidden;
							}
						}

						.list-btn {
							width: 140rpx;
							display: flex;
							flex-direction: column;
							align-items: flex-end;
							justify-content: flex-start;
						}
					}
				}
			}
		}
	}
</style>